//
//  ViewController.swift
//  LXPageView
//
//  Created by seven on 2017/11/9.
//  Copyright © 2017年 seven. All rights reserved.
//

import UIKit
private let cellIdentifer = "emojiCell"
class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let titles = ["游戏","趣玩","娱乐","美女","颜值"]
//        let titles = ["你好","美女","来一发","否","呵呵呵","傻吊哦","麻溜的来","哈哈哈哈哈哈哈哈"]
        let titleStyle = LXTitleStyle()
        titleStyle.isScrollEnable = false
        titleStyle.isIndicatorLineFlexible = false
        titleStyle.isShowIndicatorLine = true
        var childVcs = [UIViewController]()
        titles.forEach { (_) in
            let vc = UIViewController()
            vc.view.backgroundColor = UIColor.randomColor()
            childVcs.append(vc)
        }
        let pageFrame = CGRect(x: 0, y: titleStyle.safeAreaHeight, width: view.bounds.width, height: view.bounds.height)
//        创建pageView，并且加入到当前控制器
        let pageView = LXContainerView(frame: pageFrame, titles: titles, childVcs: childVcs, parentVc: self, style: titleStyle)
        view.addSubview(pageView)
        
        
//        let pageFrame = CGRect(x: 0, y: 100, width: view.bounds.width, height: 300)
//        let titles = ["土豪","热门","专属","常见"]
//        let style = LXTitleStyle()
//        style.isShowIndicatorLine = true
//        let layout = LXPageCollectionViewLayout()
//        layout.sectionInset = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
//        layout.minimumLineSpacing = 0
//        layout.minimumInteritemSpacing = 0
//
//        let pageCollectionView = LXPageCollectonView(frame: pageFrame, titles: titles, style: style, isTitleInTop: false, layout: layout)
//        pageCollectionView.register(cellClass: UICollectionViewCell.self, identifier: cellIdentifer)
//        pageCollectionView.dataSource = self
//        view.addSubview(pageCollectionView)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

extension ViewController: LXPageCollectionViewDataSource{
    func numberOfSections(in pageCollectionView: LXPageCollectonView) -> Int {
        return 4
    }
    func pageCollectionView(_ collectionView: LXPageCollectonView, numberOfItemsInSection section: Int) -> Int {
        if section == 0 {
            return 20
        }else{
            return 14
        }
    }
    func pageCollectionView(_ pageCollectionView: LXPageCollectonView, _ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellIdentifer, for: indexPath)
        cell.backgroundColor = UIColor.randomColor()
        return cell
    }
}
